home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBSYNC.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  85 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbsync.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <btree.h>
  13. #include <lseq.h>
  14.  
  15. /* local headers */
  16. #include "cbase_.h"
  17.  
  18. /*man---------------------------------------------------------------------------
  19. NAME
  20.      cbsync - synchronize cbase
  21.  
  22. SYNOPSIS
  23.      #include <cbase.h>
  24.  
  25.      int cbsync(cbp)
  26.      cbase_t *cbp;
  27.  
  28. DESCRIPTION
  29.      The cbsync function causes any buffered data for the named cbase
  30.      to be written out, both for the record and the key files.  The
  31.      cbase remains open and the buffer contents remain intact.
  32.  
  33.      cbsync will fail if one or more of the following is true:
  34.  
  35.      [EINVAL]       cbp is not a valid cbase pointer.
  36.      [EINVAL]       cbp is not open.
  37.  
  38. SEE ALSO
  39.      cbclose, cblock.
  40.  
  41. DIAGNOSTICS
  42.      Upon successful completion, a value of 0 is returned.  Otherwise,
  43.      a value of -1 is returned, and errno set to indicate the error.
  44.  
  45. ------------------------------------------------------------------------------*/
  46. #ifdef AC_PROTO
  47. int cbsync(cbase_t *cbp)
  48. #else
  49. int cbsync(cbp)
  50. cbase_t *cbp;
  51. #endif
  52. {
  53.     int i = 0;
  54.  
  55.     /* validate arguments */
  56.     if (!cb_valid(cbp)) {
  57.         errno = EINVAL;
  58.         return -1;
  59.     }
  60.  
  61.     /* check if not open */
  62.     if (!(cbp->flags & CBOPEN)) {
  63.         errno = CBENOPEN;
  64.         return -1;
  65.     }
  66.  
  67.     /* synchronize record file with buffers */
  68.     if (lssync(cbp->lsp) == -1) {
  69.         CBEPRINT;
  70.         return -1;
  71.     }
  72.  
  73.     /* synchronize key files with buffers */
  74.     for (i = 0; i < cbp->fldc; ++i) {
  75.         if (cbp->fldv[i].flags & CB_FKEY) {
  76.             if (btsync(cbp->btpv[i]) == -1) {
  77.                 CBEPRINT;
  78.                 return -1;
  79.             }
  80.         }
  81.     }
  82.  
  83.     return 0;
  84. }
  85.